//package com.hc.handle;
//
//import com.hc.exception.TlsRuntimeException;
//import com.hc.bean.ApiResponse;
//import com.hc.bean.TlsResponseEnums;
//import org.apache.ibatis.binding.BindingException;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.dao.DataAccessException;
//import org.springframework.http.HttpStatus;
//import org.springframework.stereotype.Controller;
//import org.springframework.validation.BindException;
//import org.springframework.web.bind.annotation.*;
//import org.springframework.web.servlet.NoHandlerFoundException;
//
//import javax.servlet.http.HttpServletRequest;
//import java.net.ConnectException;
//import java.sql.SQLException;
//
//@RestControllerAdvice(annotations={RestController.class,Controller.class})
//public class SpringExceptionHandle {
//
//    private static final Logger logger = LoggerFactory.getLogger(SpringExceptionHandle.class);
//
//    /**
//     * 请求参数类型错误异常的捕获
//     *
//     * @param e
//     * @return
//     */
//    @ExceptionHandler(value = {BindException.class})
//    @ResponseBody
//    @ResponseStatus(value = HttpStatus.BAD_REQUEST)
//    public ApiResponse<String> badRequest(BindException e) {
//        logger.error("occurs error when execute method ,message {}", e.getMessage());
////        return new ApiResponse<>(false, TlsResponseEnums.BAD_REQUEST);
//        return new ApiResponse<>(false, TlsResponseEnums.BAD_REQUEST);
//    }
//
//    /**
//     * 404错误异常的捕获
//     *
//     * @param e
//     * @return
//     */
//    @ExceptionHandler(value = {NoHandlerFoundException.class})
//    @ResponseBody
//    @ResponseStatus(value = HttpStatus.NOT_FOUND)
//    public ApiResponse<String> badRequestNotFound(BindException e) {
//        logger.error("occurs error when execute method ,message {}", e.getMessage());
//        return new ApiResponse<>(false, null, TlsResponseEnums.NOT_FOUND);
//    }
//
//    /**
//     * mybatis未绑定异常
//     *
//     * @param e
//     * @return
//     */
//    @ExceptionHandler(BindingException.class)
//    @ResponseBody
//    @ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
//    public ApiResponse<String> mybatis(Exception e) {
//        logger.error("occurs error when execute method ,message {}", e.getMessage());
//        return new ApiResponse<>(false, TlsResponseEnums.BOUND_STATEMENT_NOT_FOUNT);
//    }
//
//    /**
//     * 自定义异常的捕获
//     * 自定义抛出异常。统一的在这里捕获返回JSON格式的友好提示。
//     *
//     * @param exception
//     * @param request
//     * @return
//     */
//    @ExceptionHandler(value = {TlsRuntimeException.class})
//    @ResponseBody
//    @ResponseStatus(value = HttpStatus.OK)
//    public <T> ApiResponse<T> sendError(TlsRuntimeException exception, HttpServletRequest request) {
//        String requestURI = request.getRequestURI();
//        logger.error("occurs error when execute url ={} ,message {}", requestURI, exception);
//        return new ApiResponse<>(false, exception.getCode(), exception.getMessage());
//    }
//
//    /**
//     * 数据库操作出现异常
//     *
//     * @param e
//     * @return
//     */
//    @ExceptionHandler(value = {SQLException.class, DataAccessException.class})
//    @ResponseBody
//    @ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
//    public ApiResponse<String> systemError(Exception e) {
//        logger.error("occurs error when execute method ,message {}", e.getMessage());
////        return new ApiResponse<>(false, TlsResponseEnums.DATABASE_ERROR);
//        return new ApiResponse<>(false,e.getMessage());
//    }
//
//    /**
//     * 网络连接失败！
//     *
//     * @param e
//     * @return
//     */
//    @ExceptionHandler(value = {ConnectException.class})
//    @ResponseBody
//    @ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
//    public ApiResponse<String> connect(Exception e) {
//        logger.error("occurs error when execute method ,message {}", e.getMessage());
//        return new ApiResponse<>(false, TlsResponseEnums.CONNECTION_ERROR);
//    }
//
//    @ExceptionHandler(value = {Exception.class})
//    @ResponseBody
//    @ResponseStatus(value = HttpStatus.METHOD_NOT_ALLOWED)
//    public ApiResponse<String> notAllowed(Exception e) {
//        e.printStackTrace();
//        logger.error("occurs error when execute method ,message {}", e.getMessage());
//        return new ApiResponse<>(false, TlsResponseEnums.METHOD_NOT_ALLOWED);
//    }
//
//
//
//
//}
